﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using VictorBlaga.DocumentManagement.Core.Models;
using VictorBlaga.DocumentManagement.Core.Models.Repositories;
using VictorBlaga.DocumentManagement.Models;

namespace VictorBlaga.DocumentManagement.Helpers.Mappers.Impl
{
    public class WorkshopMapper : IWorkshopMapper
    {
        private IUserRepository _userRepository;
        private ITeamRepository _teamRepository;

        public WorkshopMapper(IUserRepository userRepository, ITeamRepository teamRepository)
        {
            _userRepository = userRepository;
            _teamRepository = teamRepository;
        }

        public WorkshopViewModel MapToViewModel(Workshop model)
        {
            var workshopViewModel = new WorkshopViewModel();
            if(model!=null)
            {
                workshopViewModel.Name = model.Name;
                if (model.Manager != null)
                {
                    workshopViewModel.ManagerId = model.Manager.ID;
                    workshopViewModel.ManagerName = model.Manager.Fullname;
                }
                if (model.Team != null)
                {
                    workshopViewModel.TeamName = model.Team.Name;
                    workshopViewModel.TeamId = model.Team.ID;
                }
            }
            return workshopViewModel;
        }

        public void MapToModel(WorkshopViewModel viewModel, Workshop model)
        {
            model.Name = viewModel.Name;
            model.Manager = _userRepository.GetByID((int)viewModel.ManagerId);
            model.Team = _teamRepository.GetByID((int)viewModel.TeamId);
        }
    }
}
